package gui.edit.components;

import gui.edit.enums.E_EditParamsSliders;
import gui.edit.listeners.ListenerParamBiSliderPacingChange;

import java.awt.Color;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;

import javax.swing.BorderFactory;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;

import tuio.components.BiSliderTouch;

import controls.edit.ParamControl;

import data.Constants;
import data.visu.utils.StringFormater;

/**
 * @author Charles Perin
 * 29 mars 2011
 * LIMSI - INRIA Rennes
 * charles.perin@free.fr
 *
 */
public class ParamsBiSliders_PacingPanel extends JPanel{

	/**
	 * 
	 */
	private static final long serialVersionUID = -1486667737856122711L;

	private JTextField field;
	
	private ParamControl controler;
	
	public ParamsBiSliders_PacingPanel(BiSliderTouch slider, ParamControl controler, E_EditParamsSliders editParam){
		field = new JTextField();
		this.setControler(controler);
		slider.setToolTipText(editParam.getSliderToolTip());
		String nameString = editParam.getName();
		
		nameString = StringFormater.formatString(nameString, 10);
		
		JLabel pacingLabel = new JLabel(nameString);
		pacingLabel.setFont(Constants.CAMERA_PANEL_FONT_SLIDERS_LABELS);
		pacingLabel.setPreferredSize(Constants.CAMERA_PANEL_DIMENSION_SLIDERS_NAMES);
		pacingLabel.setHorizontalAlignment(JLabel.CENTER);
		
		field.setText("0->60");
		field.setBorder(BorderFactory.createLineBorder(Color.BLACK));
		field.setPreferredSize(Constants.CAMERA_PANEL_DIMENSION_SLIDERS_VALUES);
		field.setFont(Constants.CAMERA_PANEL_FONT_SLIDERS_VALUES);
		field.setEditable(false);
		field.setHorizontalAlignment(JTextField.CENTER);

		slider.setPreferredSize(Constants.CAMERA_PANEL_DIMENSION_BISLIDERS);
		slider.setToolTipText(editParam.getSliderToolTip());
		slider.setUniformSegment(true);
		slider.setVisible(true);
		slider.setMinimumValue(editParam.getMinValue());
		slider.setMaximumValue(editParam.getMaxValue());
		slider.setSegmentSize(editParam.getMajorTickSpacing());
		slider.setMinimumColor(Color.RED);
		slider.setMaximumColor(Color.BLUE);
		slider.setColoredValues(0, 100);
		slider.setUnit("'");
		slider.setPrecise(true);
		slider.setArcSize(18);
		slider.addBiSliderListener(new ListenerParamBiSliderPacingChange(this));

		setLayout(new GridBagLayout());
		GridBagConstraints c = new GridBagConstraints();
		c.gridx=0;
		c.gridy=0;
		c.weighty=0;
		c.fill=GridBagConstraints.BOTH;
		add(pacingLabel, c);
		
		c.fill=GridBagConstraints.VERTICAL;
		c.gridy+=1;
		c.weighty=1;
		add(slider, c);
		
		c.fill=GridBagConstraints.BOTH;
		c.gridy+=1;
		c.weighty=0;
		add(field, c);
	}

	public JTextField getField() {
		return field;
	}

	public void setControler(ParamControl controler) {
		this.controler = controler;
	}

	public ParamControl getControler() {
		return controler;
	}
}
